package com.pocketsweet.ui.fragments;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.avos.avoscloud.AVAnalytics;
import com.avos.avoscloud.AVFile;
import com.lidroid.xutils.ViewUtils;
import com.pocketsweet.C;
import com.pocketsweet.MLApplication;
import com.pocketsweet.R;
import com.pocketsweet.chat.ui.activity.VoiceCallActivity;
import com.pocketsweet.chatui.domain.User;
import com.pocketsweet.chatui.utils.CommonUtils;
import com.pocketsweet.model.MLGallery;
import com.pocketsweet.model.MLGiftRecord;
import com.pocketsweet.model.MLUser;
import com.pocketsweet.service.UserService;
import com.pocketsweet.ui.Appraise;
import com.pocketsweet.ui.GiftRecord;
import com.pocketsweet.ui.LoverInvited;
import com.pocketsweet.ui.Main;
import com.pocketsweet.ui.More;
import com.pocketsweet.ui.MyEvaluation;
import com.pocketsweet.ui.MyLike;
import com.pocketsweet.ui.MyWallet;
import com.pocketsweet.ui.NewFollow;
import com.pocketsweet.ui.Privilege;
import com.pocketsweet.ui.Profile;
import com.pocketsweet.ui.Splash;
import com.pocketsweet.ui.Task;
import com.pocketsweet.ui.Wallet;
import com.pocketsweet.ui.uilib.ActionSheetDialog;
import com.pocketsweet.ui.uilib.ActionSheetDialog.OnSheetItemClickListener;
import com.pocketsweet.ui.uilib.ActionSheetDialog.SheetItemColor;
import com.pocketsweet.ui.uilib.HeaderLayout;
import com.pocketsweet.ui.uilib.HeaderLayout.onRightContainerListener;
import com.pocketsweet.ui.uilib.LoadingDailog;
import com.pocketsweet.ui.uilib.SimpleViewPagerIndicator;
import com.pocketsweet.utils.FastBlur;
import com.pocketsweet.utils.ShareReferanceUtils;
import com.pocketsweet.utils.StringUtils;
import com.pocketsweet.utils.ToolKits;
import com.pocketsweet.utils.selectPicUtils;

@SuppressLint("NewApi")
public class SelfFragment extends Fragment implements View.OnClickListener {
    static Context mContext;
    private View rootView;
    private TextView tvLikeRecomend;
    private TextView tvLikePeople;
    private TextView tvMyMoney;
    private TextView username;
    private TextView tvMolianNumber;
    private TextView tvIsTestLover;
    private ImageView imgAvatars;
    // private ImageView imgSelfBgPic;
    // private ImageView imgBlur;
    private RelativeLayout relMyProfile;
    private RelativeLayout relWallet;
    private RelativeLayout relAppraise;
    private RelativeLayout relTask;
    private RelativeLayout relGift;
    private RelativeLayout relPrivilege;
    private RelativeLayout relLovePeople;
    private RelativeLayout relLoveRecommend;
    private LinearLayout linePrivilege;
    private LinearLayout lineLoverInvited;
    private RelativeLayout relLoverInvited;
    // private LinearLayout linRecommend;

    private ImageView ivMyInvited;
    private ImageView ivLikeMe;

    private boolean hidden;

    private ViewPager mViewPager;// 页卡内容
    private List<Fragment> listViews; // Tab页面列表
    private ImageView cursor;// 动画图片
    private int offsetone = 0;// 动画图片偏移量
    private int offsetOneToTwo = 0;// 滑动距离
    private int currIndex = 0;// 当前页卡编号
    private int bmpW;// 动画图片宽度
    private Animation animation = null;
    private MLUser currentUser;
    private Uri cropPath;
    private AVFile photo;
    private Thread changeBgThread;
    public static boolean needUpdateBg = true;
    public static boolean needUpdateAvatar = true;
    public static MLGallery mGallery;
    private LoadingDailog mLoadingDialog;
    private String[] mTitles = new String[]{"喜欢的人", "喜欢的推荐"};
    private SimpleViewPagerIndicator mIndicator;
    private FragmentPagerAdapter mAdapter;
    private static final int REQUEST_CODE_SELECT_PHOTO = 0x01;
    private static final int REQUEST_CROP = 0x02;
    private static final int BG_SIZE = 4;
    public static ArrayList<String> imgsPath = new ArrayList<String>();// 将值传给编辑页面，编辑页面不用再请求网络
    public static List<AVFile> mlAVFileList = new LinkedList<AVFile>();// 已有的文件列表,

    final private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 0:
                    // applyBlur(true);// 模糊背景,有上传过背景图片
                    mLoadingDialog.dismiss();
                    break;
                default:
                    break;
            }
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_self, null);
        ViewUtils.inject(this, rootView);
        needUpdateBg = true;
        needUpdateAvatar = true;
        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mContext = getActivity();
        if (imgsPath != null) {
            imgsPath = null;
        }
        if (mlAVFileList != null) {
            mlAVFileList = null;
        }
        initView();
        // InitImageView();
        // InitViewPager();
        // initImageOffset();
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        this.hidden = hidden;
        if (!hidden) {
            refresh();// 恋爱呼叫
        }
    }

    @Override
    public void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        if (UserService.getCurrentUser() == null) {
            Intent intent = new Intent(getActivity().getApplicationContext(),
                    Splash.class);
            PendingIntent restartIntent = PendingIntent.getActivity(
                    getActivity().getApplicationContext(), 0, intent,
                    Intent.FLAG_ACTIVITY_NEW_TASK);
            AlarmManager mgr = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
            mgr.set(AlarmManager.RTC, System.currentTimeMillis(),
                    restartIntent);
            MLApplication mlApplication = MLApplication.getInstance();
            mlApplication.finishActivity();
        }
        if (UserService.getCurrentUser() == null) {
            System.exit(0);
            Intent intent = new Intent(getActivity(), Splash.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
        initMyFile();
        if (!hidden) {
            refresh();// 恋爱呼叫
        }

    }

    @Override
    public void onStop() {
        // releaseImageViews();
        super.onStop();
    }

    private void initView() {
        relMyProfile = (RelativeLayout) getActivity().findViewById(
                R.id.relMyProfile);
        relWallet = (RelativeLayout) getActivity().findViewById(R.id.relWallet);
        linePrivilege = (LinearLayout) getActivity().findViewById(
                R.id.linePrivilege);
        lineLoverInvited = (LinearLayout) getActivity().findViewById(
                R.id.lineLoverInvited);
        relAppraise = (RelativeLayout) getActivity().findViewById(
                R.id.relAppraise);
        relPrivilege = (RelativeLayout) getActivity().findViewById(
                R.id.relPrivilege);
        relLoverInvited = (RelativeLayout) getActivity().findViewById(
                R.id.relLoverInvited);
        relLovePeople = (RelativeLayout) getActivity().findViewById(
                R.id.relLovePeople);
        relLoveRecommend = (RelativeLayout) getActivity().findViewById(
                R.id.relLoveRecommend);
        relTask = (RelativeLayout) getActivity().findViewById(R.id.relTask);
        relGift = (RelativeLayout) getActivity().findViewById(R.id.relGift);
        relPrivilege = (RelativeLayout) getActivity().findViewById(
                R.id.relPrivilege);
        imgAvatars = (ImageView) getActivity().findViewById(R.id.imgAvatars);
        ivLikeMe = (ImageView) getActivity().findViewById(R.id.ivLikeMe);
        // imgBlur = (ImageView) getActivity().findViewById(R.id.imgBlur);
        // imgSelfBgPic = (ImageView) getActivity()
        // .findViewById(R.id.imgSelfBgPic);
        username = (TextView) getActivity().findViewById(R.id.username);
        tvMolianNumber = (TextView) getActivity().findViewById(
                R.id.tvMolianNumber);
        tvIsTestLover = (TextView) getActivity().findViewById(
                R.id.tvIsTestLover);
        tvMyMoney = (TextView) getActivity().findViewById(R.id.tvMyMoney);
        ivMyInvited = (ImageView) getActivity().findViewById(R.id.imgMyInvited);
        relMyProfile.setOnClickListener(this);
        relWallet.setOnClickListener(this);
        relLoverInvited.setOnClickListener(this);
        relLovePeople.setOnClickListener(this);
        relLoveRecommend.setOnClickListener(this);
        relTask.setOnClickListener(this);
        relGift.setOnClickListener(this);
        relAppraise.setOnClickListener(this);
        relPrivilege.setOnClickListener(this);
        // imgSelfBgPic.setOnClickListener(this);
        imgAvatars.setOnClickListener(this);
        currentUser = UserService.getCurrentUser();
        // BG_SIZE = getResources().getDimensionPixelSize(R.dimen.myMargin);
        mLoadingDialog = ToolKits.createLoadingDialog(getActivity(), "上传中");
        // 背景
        int currentapiVersion = android.os.Build.VERSION.SDK_INT;// 获取API版本，只有API版本大于17才可以模糊？
    }

    private void initMyFile() {
        // 头像
        currentUser = UserService.getCurrentUser();
        if (currentUser == null) {
            return;
        }
        // if (needUpdateBg == true || imgSelfBgPic.getDrawable() == null) {
        // // load背景
        // String backgroundUrl = currentUser.getBackgroundbaUrl();
        // if (!StringUtils.isEmpty(backgroundUrl)) {
        // UserService.displayBgImage(currentUser.getBackground()
        // .getUrl(), imgSelfBgPic);
        // // if (currentapiVersion >= 17) {
        // // applyBlur(true);// 模糊背景,有上传过背景图片
        // // }
        // } else {
        // UserService.displayDrawableImage(
        // R.drawable.img_user_info_bg, imgSelfBgPic);
        // // imgSelfBgPic.setImageBitmap(MyBitmapFactory
        // // .decodeSampledBitmapFromResource(getResources(),
        // // R.drawable.img_user_info_bg, 600, 600));
        // //
        // Picasso.with(getActivity()).load(R.drawable.img_user_info_bg).into(imgSelfBgPic);
        // // imgSelfBgPic.setImageDrawable(getResources().getDrawable(
        // // R.drawable.img_user_info_bg));
        // // if (currentapiVersion >= 17) {
        // // applyBlur(false);// 模糊背景，没上传过
        // // }
        // }
        // needUpdateBg = false;
        // }
        if (needUpdateAvatar == true || imgAvatars.getDrawable() == null) {
            String avatar = currentUser.getSubAvatar() != null ? currentUser
                    .getSubAvatar() : currentUser.getAvatarUrl();
            if (!StringUtils.isEmpty(avatar)) {
                // UserService.displayAvatar(avatar, imgAvatars);
                UserService.displaySquare(avatar, imgAvatars);
            }
            needUpdateAvatar = false;
        }
        if (!StringUtils.isEmpty(currentUser.getNickname())) {
            username.setText(currentUser.getNickname());
            username.setVisibility(View.VISIBLE);
        }
        if (!StringUtils.isEmpty(String.valueOf(currentUser.getMolianId()))) {
            tvMolianNumber.setText("袋号:"
                    + String.valueOf(currentUser.getMolianId()));
            tvMolianNumber.setVisibility(View.VISIBLE);
        }
        if (currentUser.getType() == C.USER_TYPE_NORMAL) {
            tvIsTestLover.setText("实习恋人");
            tvIsTestLover.setVisibility(View.VISIBLE);
            relPrivilege.setVisibility(View.GONE);
            linePrivilege.setVisibility(View.GONE);
            relLoverInvited.setVisibility(View.GONE);
            lineLoverInvited.setVisibility(View.GONE);

        } else {
            // tvIsReCommanded.setText("恋爱体验师");
            if (currentUser.getType() == C.USER_TYPE_LOVER) {
                tvIsTestLover.setText("口袋恋人");
            } else {
                tvIsTestLover.setText("梦想恋人");
            }
            tvIsTestLover.setVisibility(View.VISIBLE);
            relPrivilege.setVisibility(View.GONE);
            linePrivilege.setVisibility(View.GONE);
            relLoverInvited.setVisibility(View.VISIBLE);
            lineLoverInvited.setVisibility(View.VISIBLE);
        }
        // if (currentUser.getBalance() == 0) {
        // tvMyMoney.setText("0元");
        // } else {
        // tvMyMoney.setText(currentUser.getBalance() + "元");
        // }
    }

    // private void applyBlur(final boolean isOnLineBg) { // 模糊
    // imgSelfBgPic.getViewTreeObserver().addOnPreDrawListener(
    // new ViewTreeObserver.OnPreDrawListener() {
    // @Override
    // public boolean onPreDraw() {
    // imgSelfBgPic.getViewTreeObserver()
    // .removeOnPreDrawListener(this);
    // imgSelfBgPic.buildDrawingCache();
    // Bitmap bmp;
    // if (isOnLineBg) {
    // bmp = ImageLoader.getInstance().loadImageSync(
    // currentUser.getBackground().getUrl());
    // } else {
    // bmp = imgSelfBgPic.getDrawingCache();
    // }
    // blur(bmp, imgBlur);
    // return true;
    // }
    // });
    // }

    private void blur(Bitmap bkg, View view) { // 模糊
        long startMs = System.currentTimeMillis();
        float scaleFactor = 1;
        float radius = 20;
        Bitmap overlay = Bitmap.createBitmap(
                (int) (view.getMeasuredWidth() / scaleFactor),
                (int) (view.getMeasuredHeight() / scaleFactor),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(overlay);
        canvas.translate(-view.getLeft() / scaleFactor, -view.getTop()
                / scaleFactor);
        canvas.scale(1 / scaleFactor, 1 / scaleFactor);
        Paint paint = new Paint();
        paint.setFlags(Paint.FILTER_BITMAP_FLAG);
        canvas.drawBitmap(bkg, 0, 0, paint);

        overlay = FastBlur.doBlur(overlay, (int) radius, true);
        view.setBackground(new BitmapDrawable(getResources(), overlay));
    }

    public static void setHeaderFunction() {
        HeaderLayout header = Main.getInstance().getHeader();
        header.setRighttContainerClickListener(new onRightContainerListener() {
            @Override
            public void onClick() {
                Intent intent = new Intent(mContext, More.class);
                mContext.startActivity(intent);
            }
        });
    }

    /*
     * 更换背景图片
     */
    public void changeBackGround(View view) {
        new ActionSheetDialog(getActivity())
                .builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(true)
                .addSheetItem("从相册选择", SheetItemColor.Gray,
                        new OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                Intent intent = new Intent();
                                intent.setDataAndType(
                                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                                        "image/*");
                                intent.setAction(Intent.ACTION_GET_CONTENT);
                                startActivityForResult(intent,
                                        REQUEST_CODE_SELECT_PHOTO);
                                // selectPicUtils.openLocalImage(getActivity());
                            }
                        })
                .addSheetItem("拍照", SheetItemColor.Gray,
                        new OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                selectPicUtils.openCameraImage(getActivity());
                            }
                        }).show();
    }

    // @Override
    // public void onActivityResult(int requestCode, int resultCode, Intent
    // data) {
    // super.onActivityResult(requestCode, resultCode, data);
    // if (resultCode == Activity.RESULT_CANCELED) {
    // return;
    // }
    // switch (requestCode) {
    // case selectPicUtils.GET_IMAGE_BY_CAMERA: // 拍照上传
    // Uri url = selectPicUtils.imageUriFromCamera;
    // if (url != null) {
    // String sImagePath = ToolKits.getImgRealPathFromURI(url,
    // getActivity());
    // String copressPath = sImagePath + "_bg";
    // WindowManager wm = (WindowManager) getActivity()
    // .getSystemService(Context.WINDOW_SERVICE);
    // int width = wm.getDefaultDisplay().getWidth();
    // int height = wm.getDefaultDisplay().getHeight();
    // selectPicUtils.cropBgImage(getActivity(),
    // selectPicUtils.imageUriFromCamera, width, width, width,
    // width);
    // }
    // break;
    // case REQUEST_CODE_SELECT_PHOTO: // 选择图片上传
    // if (null != data) {
    // Uri url1 = data.getData();
    // String ImagePath = ToolKits.getImgRealPathFromURI(url1,
    // getActivity());
    // File file = new File(ImagePath);
    // cropPath = Uri
    // .parse("file://" + file.getAbsolutePath() + "_bg");
    // startPhotoZoom(url1);
    // }
    // break;
    // case selectPicUtils.CROP_IMAGE: // 拍照后的回调
    // if (selectPicUtils.cropImageUri != null) {
    // File avatarCrop = selectPicUtils.createFileFromUri(
    // selectPicUtils.cropImageUri, getActivity());
    // try {
    // photo = AVFile.withAbsoluteLocalPath(avatarCrop.getName(),
    // avatarCrop.getAbsolutePath());
    // mLoadingDialog.show();
    // // 获取当前的用户
    // final MLUser user = UserService.getCurrentUser();
    // user.setBackground(photo);
    // user.saveInBackground(new SaveCallback() { // 保存背景
    //
    // @Override
    // public void done(AVException arg0) {
    // // TODO Auto-generated method stub
    // if (arg0 == null) {
    // UserService.displayBigImage(
    // user.getBackgroundbaUrl(), imgSelfBgPic);
    // changeBgThread = new Thread(new Runnable() { // 异步线程更改上传的图片并且模糊后的ui
    // @Override
    // public void run() {
    // try {
    // mHandler.sendEmptyMessage(0);
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    // }
    // });
    // changeBgThread.start();
    // } else {
    // mLoadingDialog.dismiss();
    // }
    // }
    // });
    // } catch (FileNotFoundException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // } catch (IOException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    // }
    // break;
    // case REQUEST_CROP: // 选择头像后的回调
    // String ImagePath = ToolKits.getImgRealPathFromURI(cropPath,
    // getActivity());
    // File avatarCrop = new File(ImagePath);
    // if (avatarCrop.exists()) {
    // // 头像需要显示到界面上
    // try {
    // photo = AVFile.withAbsoluteLocalPath(avatarCrop.getName(),
    // avatarCrop.getAbsolutePath());
    // mLoadingDialog.show();
    // // 获取当前的用户
    // final MLUser user = UserService.getCurrentUser();
    // user.setBackground(photo);
    // user.saveInBackground(new SaveCallback() { // 保存背景
    //
    // @Override
    // public void done(AVException arg0) {
    // // TODO Auto-generated method stub
    // if (arg0 == null) {
    // needUpdateBg = true;
    // UserService.displayBigImage(
    // user.getBackgroundbaUrl(), imgSelfBgPic);
    // changeBgThread = new Thread(new Runnable() { // 异步线程更改上传的图片并且模糊后的ui
    // @Override
    // public void run() {
    // try {
    // mHandler.sendEmptyMessage(0);
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    // }
    // });
    // changeBgThread.start();
    // } else {
    // mLoadingDialog.dismiss();
    // }
    // }
    // });
    // } catch (FileNotFoundException e) {
    // e.printStackTrace();
    // } catch (IOException e) {
    // e.printStackTrace();
    // }
    // } else {
    // ToolKits.toast(getActivity(), "文件不存在！");
    // }
    // default:
    // break;
    // }
    // }

    /**
     * 裁剪图片方法实现
     *
     * @param uri
     */
    public void startPhotoZoom(Uri uri) {
        WindowManager wm = (WindowManager) getActivity().getSystemService(
                Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        int height = wm.getDefaultDisplay().getHeight();
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");
        // 下面这个crop=true是设置在开启的Intent中设置显示的VIEW可裁剪
        intent.putExtra("crop", "true");
        // aspectX aspectY 是宽高的比例
        intent.putExtra("aspectX", width);
        intent.putExtra("aspectY", width);
        // outputX outputY 是裁剪图片宽高
        intent.putExtra("outputX", width);
        intent.putExtra("outputY", width);
        intent.putExtra("return-data", false);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, cropPath);
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
        intent.putExtra("noFaceDetection", true);
        intent.putExtra("scale", true);
        intent.putExtra("scaleUpIfNeeded", true);
        startActivityForResult(intent, REQUEST_CROP);
    }

    @Override
    public void onClick(View arg0) {
        switch (arg0.getId()) {
            // case R.id.tvLikePeople:
            // mPager.setCurrentItem(0);
            // tvLikePeople.setTextColor(getResources().getColor(
            // R.color.main_text_color));
            // tvLikeRecomend.setTextColor(getResources()
            // .getColor(R.color.my_name));
            // break;
            // case R.id.tvLikeRecomend:
            // mPager.setCurrentItem(1);
            // tvLikeRecomend.setTextColor(getResources().getColor(
            // R.color.main_text_color));
            // tvLikePeople.setTextColor(getResources().getColor(R.color.my_name));
            // break;
            case R.id.relWallet:
                Intent intent;
                if (currentUser.getType() == C.USER_TYPE_NORMAL) {
                    intent = new Intent(getActivity(), Wallet.class);
                } else {
                    intent = new Intent(getActivity(), MyWallet.class);
                }
                intent.putExtra("balance", currentUser.getBalance());
                startActivity(intent);
                AVAnalytics.onEvent(getActivity(), "我的钱包充值");
                break;
            case R.id.relTask:
                Intent intent2 = new Intent(getActivity(), Task.class);
                startActivity(intent2);
                AVAnalytics.onEvent(getActivity(), "奖励页面访问");
                break;
            case R.id.relGift:
                Intent giftiIntent = new Intent(getActivity(), GiftRecord.class);
                startActivity(giftiIntent);
//			AVAnalytics.onEvent(getActivity(), "奖励页面访问");
                break;
            case R.id.relPrivilege:
                Intent intent3 = new Intent(getActivity(), Privilege.class);
                startActivity(intent3);
                break;
            // case R.id.imgSelfBgPic:
            // changeBackGround(arg0);
            // break;
            case R.id.relMyProfile:
                if (!CommonUtils.isNetWorkConnected(getActivity())) {
                    ToolKits.toast(getActivity(), "世界上最遥远的距离就是断网");
                    return;
                }
                Intent relMyProfileintent4 = new Intent(getActivity(),
                        Profile.class);
                relMyProfileintent4.putExtra("userId",
                        UserService.getCurrentUserId());
                relMyProfileintent4.putExtra("nickname", UserService
                        .getCurrentUser().getNickname());
                startActivity(relMyProfileintent4);
                break;
            case R.id.imgAvatars:
                Intent intent4 = new Intent(getActivity(), Profile.class);
                intent4.putExtra("userId", UserService.getCurrentUserId());
                intent4.putExtra("nickname", UserService.getCurrentUser()
                        .getNickname());
                startActivity(intent4);
                break;
            case R.id.relLovePeople:
                Intent relLovePeopleIntent = new Intent(getActivity(),
                        NewFollow.class);
                getActivity().startActivity(relLovePeopleIntent);
                AVAnalytics.onEvent(getActivity(), "喜欢我的页面访问");
                // Intent intent5 = new Intent(getActivity(), LikePeople.class);
                // startActivity(intent5);
                break;
            case R.id.relLoveRecommend:
                Intent intent6 = new Intent(getActivity(), MyLike.class);
                AVAnalytics.onEvent(getActivity(), "我喜欢的页面访问");
                startActivity(intent6);
                break;
            case R.id.relAppraise:
                if (UserService.getCurrentUser().getType() != C.USER_TYPE_NORMAL) {
                    Intent intent7 = new Intent(getActivity(), MyEvaluation.class);
                    getActivity().startActivity(intent7);
                } else {
                    Intent relAppraiseIntent = new Intent(getActivity(),
                            Appraise.class);
                    startActivity(relAppraiseIntent);
                }
                AVAnalytics.onEvent(getActivity(), "评价页面访问");
                break;
            case R.id.relLoverInvited:
                Intent intent7 = new Intent(getActivity(), LoverInvited.class);
                startActivity(intent7);
                AVAnalytics.onEvent(Main.getInstance(), "情感热线点击（口袋恋人）");
                break;
            default:
                break;
        }

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        needUpdateBg = true;
        needUpdateAvatar = true;
    }

    public void refresh() {
        // 刷新恋爱呼叫和喜欢的人的界面
        ShareReferanceUtils unreadCustomazitonCount = new ShareReferanceUtils(
                MLApplication.getContext(), "UnreadCustomaziton_"
                + UserService.getCurrentUserId());
        int count = unreadCustomazitonCount.getIntValue("count", 0);
        if (count == 0) {
            if (ivMyInvited != null) {
                ivMyInvited.setVisibility(View.INVISIBLE);
            }
        } else {
            if (ivMyInvited != null) {
                ivMyInvited.setVisibility(View.VISIBLE);
            }
        }
//        Intent intent = new Intent();
//        intent.setAction(Main.ACTION_NEW_INVITED);
//        getActivity().sendBroadcast(intent);

        // TODO 这里刷新喜欢的人的红点，跟上面一样
        ShareReferanceUtils unreadLikerCount = new ShareReferanceUtils(
                MLApplication.getContext(), "UnreadLiker_"
                + UserService.getCurrentUserId());
        int count1 = unreadLikerCount.getIntValue("count", 0);
        if (count1 == 0) {
            ivLikeMe.setVisibility(View.INVISIBLE);
        } else {
            ivLikeMe.setVisibility(View.VISIBLE);
        }
    }

}
